package com.briup.day23;

import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Scanner;

public class Test_ByteArrayInput {
    public static void main(String[] args) throws Exception {
        //将输入的字符串转为byte数组 使用内存输入流读取数组数据
//        将读取数据写入b.txt
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入字符串");
        String str = sc.nextLine();
        byte[] bytes = str.getBytes();
        //创建内存输入流
        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
        //输出流
        OutputStream os = new FileOutputStream("01-Basic/src/dir/b.txt");
        int len;
        byte[] buf = new byte[8];
        while((len=bais.read(buf))!=-1){
            os.write(buf,0,len);
        }
        System.out.println("写入完成");
        os.close();
    }
}
